<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item :label="$t('核销时间')">
              <j-date
                :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss" dateFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('请选择开始时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_begin"
              ></j-date>
              <span class="query-group-split-cust"></span>
              <j-date
                :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss" dateFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('请选择结束时间')"
                class="query-group-cust"
                v-model="queryParam.createTime_end"
              ></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('数字彩票票号')">
              <a-input :placeholder="$t('请输入数字彩票票号')" v-model="queryParam.lotteryNo"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('票类型')">
                <j-dict-select-tag
                  :placeholder="$t('请选择票类型')"
                  v-model="queryParam.type"
                  dictCode="bis_member_lottery.type"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('操作员')">
                <j-dict-select-tag
                  :placeholder="$t('请选择操作员')"
                  v-model="queryParam.createBy"
                  dictCode="sys_user,realname,realname"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('设备名称')">
                <j-dict-select-tag
                  :placeholder="$t('请选择设备名称')"
                  v-model="queryParam.deviceId"
                  dictCode="bis_device_info,name,id"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('会员信息')">
                <a-input :placeholder="$t('请输入手机号/卡号/姓名')" v-model="queryParam.memberInfo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('业务渠道')">
                <j-dict-select-tag
                  :placeholder="$t('请选择业务渠道')"
                  v-model="queryParam.deviceType"
                  dictCode="bis_device_info.type"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('关联订单号')">
                <a-input :placeholder="$t('请输入')" v-model="queryParam.subOrderId"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="!tenantid">
              <a-form-item :label="$t('门店')">
                <a-select v-model="queryParam.tenantId">
                  <a-select-option v-for="(item, i) in shops" :key="i" :value="item.value"
                  >{{ item.title }}<span v-if="item.value != ''">（{{ item.value }}）</span></a-select-option
                  >
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{$t('查询')}}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{$t('重置')}}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-has="'BisMemberLotteryUseController:export'" type="primary" icon="download" :loading="exloading" @click="handleExportXls($t('数字彩票核销记录'))">{{$t('导出')}}</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :customHeaderRow="customHeaderRow"
        :customRow="customRow"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{$t('无图片')}}</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{$t('无文件')}}</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            {{$t('下载')}}
          </a-button>
        </template>
        <template slot="footer">
          <div style="font-weight: bold">
            <span style="margin-left: 15px;margin-right: 5px">{{$t('票值')}}：</span>
            <span>{{ totalInfo&&totalInfo.value?totalInfo.value.toFixed(2):'0.00' }}</span>
          </div>
        </template>
      </a-table>
    </div>

    <bis-member-lottery-use-modal ref="modalForm" @ok="modalFormOk"></bis-member-lottery-use-modal>
  </a-card>
</template>

<script>
import Vue from 'vue'
import moment from 'moment'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { initDictOptions, filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import BisMemberLotteryUseModal from './modules/BisMemberLotteryUseModal'

export default {
  name: 'BisMemberLotteryUseList',
  mixins: [mixinDevice,JeecgListMixin],
  components: {
    BisMemberLotteryUseModal,
  },
  data() {
    return {
      description: '数字彩票核销记录管理页面',
      moment,
      tenantid: Vue.ls.get('TENANT_ID'),
      // 表头
      columns: [
        {
          title: this.$t('时间'),
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: this.$t('手机号'),
          align: 'center',
          dataIndex: 'phone',
        },
        {
          title: this.$t('卡号'),
          align: 'center',
          dataIndex: 'chipNo',
        },
        {
          title: this.$t('姓名'),
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: this.$t('数字彩票票号'),
          align: 'center',
          dataIndex: 'lotteryNo',
          customRender:function(t,r){
            if(t && t != null){
              return t
            }
          },
        },
        {
          title: this.$t('类型'),
          align: 'center',
          dataIndex: 'type_dictText',
        },
        {
          title: this.$t('票值'),
          align: 'center',
          dataIndex: 'value',
          customRender:function(t,r){
            return t.toFixed(2)
          },
          customCell:function(col){
            return{
              style:{
                textAlign:'right',
              }
            }
          }
        },
        {
          title: this.$t('操作员'),
          align: 'center',
          dataIndex: 'createBy',
        },
        {
          title: this.$t('业务渠道'),
          align: 'center',
          dataIndex: 'deviceType_dictText',
        },
        {
          title: this.$t('设备名称'),
          align: 'center',
          dataIndex: 'deviceId_dictText',
        },
        {
          title: this.$t('设备编码'),
          align: 'center',
          dataIndex: 'deviceId',
        },
        {
          title: this.$t('关联订单号'),
          align: 'center',
          dataIndex: 'subOrderId',
        },
      ],
      url: {
        list: '/member/bisMemberLotteryUse/list',
        delete: '/member/bisMemberLotteryUse/delete',
        deleteBatch: '/member/bisMemberLotteryUse/deleteBatch',
        exportXlsUrl: '/member/bisMemberLotteryUse/exportXls',
        importExcelUrl: 'member/bisMemberLotteryUse/importExcel',
        totalUrl: '/member/bisMemberLotteryUse/total'
      },
      dictOptions: {},
      superFieldList: [],
      queryParam:{
        createTime_begin:'',
        createTime_end:'',
        memberLotteryId:'',
        type:undefined,
        createBy:undefined,
        deviceId:undefined,
        lotteryType:1,
        tenantId: '',
      },
      isfooter:true,
      isCustom:true,
      isHideData:false,
      shops: []
    }
  },
  created() {
    if (!this.tenantid) {
      let dtl = {
          title: this.$t('门店编码'),
          align: 'center',
          dataIndex: 'tenantId',
          width: 100,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        },
        dtl1 = {
          title: this.$t('门店名称'),
          align: 'center',
          dataIndex: 'tenantId_dictText',
          width: 140,
          customCell: (r, i) => {
            return {
              style: {
                whiteSpace: 'normal',
              },
            }
          },
        }
      this.columns.unshift(dtl1)
      this.columns.unshift(dtl)
    }
  },
  mounted(){
    let that=this
    document.onkeydown = function(e) { 
      let key = window.event.keyCode; 
      if (key== 75 && event.ctrlKey) {
        window.event.preventDefault()
        that.isHideData = false
        that.queryParam.dataType=0
        that.searchQuery()
      }
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {
      initDictOptions('bis_shop,name,code').then((res) => {
        if (res.success) {
          this.shops = res.result
          this.shops.unshift({ value: '', title: this.$t('全部') })
        }
      })
      this.customInit()
    },
    customInit() {
      this.isHideData = true
      this.queryParam.dataType=1
      this.loadData(1)
    },
    modalFormOk() {
      this.loadData(1)
    },
    searchReset(){
      this.queryParam={
        createTime_begin:'',
        createTime_end:'',
        memberLotteryId:'',
        type:undefined,
        createBy:undefined,
        deviceId:undefined,
        lotteryType:1,
        tenantId: ''
      }
      this.selectedRowIndex = []
      this.customInit()
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>